<!-- 供应商管理 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form layout='inline'>
               <a-row :gutter='48'>
                    <a-col :md='8' :sm='24'>
                        <a-form-item label="供应商">
                            <a-input v-model="companyName" placeholder="请输入供应商名称" allow-clear></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                        <a-form-item label="手机号">
                            <a-input v-model="contactPhone" placeholder="请输入手机号" allow-clear></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md='6' :sm='24'>
                        <a-form-item label="状态">
                            <a-select v-model="state" placeholder="请选择" @change="getData">
                                <a-select-option v-for="item in statusList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md='6' :sm='24'>
                        <a-form-item label="费率状态">
                            <a-select v-model="serviceRateStatus" placeholder="请选择" @change="getData">
                                <a-select-option v-for="item in serviceRateStatusList" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md='10' :sm='24'>
                        <a-form-item label="时间">
                            <a-range-picker @change="onDateChange" />
                        </a-form-item>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                        <a-form-item >
                            <a-button type='primary' @click="getData">查询</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>  

        <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange" :pagination="{ total: total ,showSizeChanger: true,pageSize: size,}" size="small" :scroll="{ x: 1200, }">
            <div slot="serviceRate" slot-scope="serviceRate">
                <div>{{serviceRate ?? 0}}%</div>
            </div>
            <div slot="serviceRateStatus" slot-scope="serviceRateStatus">
                <div v-for="(item,i) in serviceRateStatusList" :key="item.id">
                    <a-tag v-if="item.id == serviceRateStatus" :color="colors[i%13]">{{item.name}}</a-tag>
                </div>
            </div>
            <div slot="state" slot-scope="state">
                <a-badge :status="state | statusTypeFilter" :text="state | statusFilter" />
            </div>
            <div slot="operation" slot-scope="text,record">
                <div class="editable-row-operations">
                    <a-button type="link" @click="detail(record)">详情</a-button>
                </div>
            </div>
        </a-table>

        <!-- 预览图片 -->
        <a-modal :visible="previewVisible" :footer="null" @cancel="previewVisible = false">
            <img alt="example" style="width: 100%" :src="previewImage" />
        </a-modal>
    </div>
</template>

<script>
import { columns } from './table';
import { getBase64 , fileProcess } from '@/utils/util';
import { queryCompanyList , createCompany , updateCompanyState } from '@/api/services/company';
import { getCustomerCompanys } from '@/api/companys/company';
import { fileUpload } from '@/api/system';
export default {
    data () {
        return {
            companyName: '', // 供应商名称
            contactPhone: '', // 手机号
            startTime: '',
            endTime: '',
            columns,
            page: 1,
            size: 10,
            isload: false,
            dataList: [],
            total: 0,
            state: undefined, // 状态
            statusList: [
                { id: 0, name: '已停用'},
                { id: 1, name: '使用中'},
            ],
            serviceRateStatus: undefined, // 实名状态
            serviceRateStatusList: [
                { id: 0, name: '未设置'},
                { id: 1, name: '已设置'},
            ],
            visible: false,
            colors: ['blue','purple','cyan','green','orange','red','pink','brown','indigo','lime','purple','teal','yellow','amber'],
            company: {
                id: '',
                companyName: '', // 公司名称
                businessLicense: '', // 营业执照图片URL
                socialCode: '', // 统一社会信用代码
                contactName: '', // 姓名
                contactPhone: '', // 手机号
                remark: '', // 备注
            },
            fileList: [],
            previewVisible: false,
            previewImage: '',
            rules: {
                companyName: [
                    { required: true, message: '请输入公司名称', trigger: 'blur' },
                ],
                socialCode: [{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }],
                businessLicense: [{required: true, message: '请上传营业执照', trigger: 'change'}, ] 
            },
        };
    },
    created(){
        this.getData();
    },
    methods: {
        // 日期筛选
        onDateChange(date,dateStr){
            console.log(date,dateStr)
            if(date.length > 0){
                this.startTime = date[0].format('YYYY-MM-DD')
                this.endTime = date[1].format('YYYY-MM-DD')
            }else{
                this.startTime = ''
                this.endTime = ''
            }
            this.getData()
        },
        // 获取供应商列表数据
        getData(){
            let _this = this
            _this.isload = true;
            const params = {
                'startTime': _this.startTime,
                'endTime': _this.endTime,
                'companyName': _this.companyName,
                'contactPhone': _this.contactPhone,
                'state': _this.state,
                'serviceRateStatus': _this.serviceRateStatus,
                'pageSize': _this.size,
                'pageIndex': _this.page,
            }
            getCustomerCompanys(params)
            .then(res=>{
                _this.isload = false;
                if(res.success){
                    _this.dataList = res.data;
                    _this.total = res.totalCount;
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 查看详情
        detail(item){
            this.$router.push({ path: '/companysCompany/companyDetail', query: { 'detail': JSON.stringify(item)}})
        },
    }
}

</script>
<style scoped>

</style>